<!DOCTYPE html>
<html lang="en">

<head>
  <!-- 因为引入了koa-static 所以src文件无法在这里打开 -->
  <link rel="stylesheet" type="text/css" href="/css/home.css">
  <!-- <style type="text/css" >@import url(/css/home.css);</style> -->

</head>

<body>
  <div class="content box">
    <button onclick="getTest()" class="f">点击测试get方法</button>
    <button onclick="postTest()">点击测试POST方法</button>


    <span>Name：</span>
    <input id="tname" name="tname" value="A1" />
    sexy <input id="sexy" name="sexy" value="U" />
  </div>


  <script src="/js/jquery-3.6.0.min.js"></script>
  <script>
    var getTest = () => {
      $.ajax({
        type: 'GET',
        url: `/getData?name=${$('#tname').val()}&sexy=${$('#sexy').val()}`,
        dataType: 'json',
        success(data) {
          console.log(data);
        },
        error(err) {
          console.log(err);
        }
      });
    }
    var postTest = () => {
      var obj = {}
      obj = {
        name: $('#tname').val(),
        sexy: $('#sexy').val()
      }
      console.log(obj)
      $.ajax({
        type: 'POST',
        url: '/addUser',
        data: obj,
        dataType: 'json',
        success(data) {
          console.log(data);
        },
        error(err) {
          console.log(err);
        }
      });
    }
  </script>
</body>

</html>